<template>
	<view class="commonQuestionContainer">
		<block v-if="questionList.length > 0">
			<scroll-view :scroll-y="isScroll" :style="{ height: windowHeight + 'px' }"@scrolltolower="lower" :scroll-top="scrollTop">
				<view class="questionItem flex" v-for="item,index in questionList" :key="index" @click="jumpPage(item.article_id)">
					<view class="questionLabel txtOverFlow">{{item.article_name}}</view>
					<image src="../../static/images/moreIconHui.png" class="moreIconHui"></image>
				</view>
			</scroll-view>
		</block>
		<view v-else class="noDataTxt">暂无数据</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page:1,
				limit: 20,
				hasMoreData: false,//是否还有更多数据
				isScroll: true,
				windowHeight: 0,
				scrollTop: 0,
				questionList: []
			}
		},
		onLoad() {
			let _this = this;
			wx.getSystemInfo({
				success: function(res) {
					_this.windowHeight = res.windowHeight;
				}
			})
		},
		onShow() {
			this.searchQuestionList();
		},
		methods: {
			jumpPage(articleId) {
				uni.navigateTo({
					url: '/pages/articleInfo/articleInfo?articleId='+articleId
				});
			},
			searchQuestionList() {
				let _this = this;
				this.$utils.requestFun('/base/article/api/selectAritcleByTypeId?route=base',{
					token: getApp().globalData.token,
					appId: getApp().globalData.appid,
					channelId: getApp().globalData.channelId,
					pageNum: _this.page,
					pageSize: _this.limit
				},'GET').then(res=> {
					let questionListData = _this.questionList;
					if(res.data.data.data && res.data.data.data.length > 0) {
						if(_this.page == 1) {
							questionListData = [];
						}
						let questionList = res.data.data.data;
						if(questionList.length < _this.limit) {
							_this.questionList = questionListData.concat(questionList);
							_this.hasMoreData = false;
						}else {
							_this.questionList = questionListData.concat(questionList);
							_this.hasMoreData = true;
							_this.page = _this.page++;
						}
					}else {
						if(_this.page == 1) {
							_this.questionList = [];
						}else {
							_this.questionList = questionListData;
						}
					}
				});
			},
			lower(e) {
				if (this.hasMoreData) {
					let page = this.page+1;
					this.page = page;
					this.searchQuestionList();
				} else {
					uni.showToast({
						title: '没有更多数据',
						icon: 'none'
					})
				}
			},
		}
	}
</script>

<style>
	.commonQuestionContainer {
		width: 100%;
		height: 100vh;
		background: #FFFFFF;
	}
	.txtOverFlow {
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
	}
	.flex {
		display: flex;
	}
	.questionItem {
		width: 94%;
		height: 110rpx;
		margin: 0 25rpx;
		border-bottom: 1px solid #EEEEEE;
	}
	.questionLabel {
		width: 97%;
		text-align: left;
		font-size: 32rpx;
		color: #222222;
		line-height: 110rpx;
	}
	.moreIconHui {
		width: 22rpx;
		height: 24rpx;
		margin-top: 46rpx;
	}
</style>
